home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 632 < prev    next >
Internet Message Format  |  1996-08-06  |  1KB

  1. Path: news.compuserve.com!newsmaster
  2. From: JamesCurran@CIS.CompuServe.com (James M. Curran)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Restrictions on qsort compare function?
  5. Date: Fri, 22 Mar 1996 21:07:02 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4iv4rf$frk@dub-news-svc-3.compuserve.com>
  8. References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com> <4iukhc$5nr@rdsunx.crd.ge.com>
  9. NNTP-Posting-Host: dd75-092.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. In <<4iukhc$5nr@rdsunx.crd.ge.com>>, 
  13. volpe@bart.crd.ge.com (Christopher R. Volpe) wrote:
  14.  
  15.  
  16. >Alternatively, how about this:
  17.  
  18. >    return ((signed int) ((unsigned int)a - (unsigned int)b));
  19.  
  20.  
  21.     That won't work.  First consider a=-32 and b = 31, which, with 16-bit
  22. ints becomes:
  23.    (signed int) ( (unsigned int) -32 - (unsigned int) 31 )
  24. == (signed int)                65504 -                31  
  25. == (signed int)                65473 
  26. == -63 (a negative value, as it should)
  27.  
  28.     Now, multiple each value by 1000.  Since the relationship is the same,
  29. we should again get a negative number, however:
  30.    (signed int) ( (unsigned int) -32000 - (unsigned int) 31000 )
  31. == (signed int) (                 33536 -                31000)
  32. == (signed int) (                  2536)
  33. == 2536 (a positiove value)
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.